﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gds.ViewModel.pageViewModel
{

    public class ClientConfigVm : INotifyPropertyChanged
    {
        #region defaultPart
        private static volatile ClientConfigVm _instance;
        private static object _instanceLock = new object();
        public static ClientConfigVm Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_instanceLock)
                    {
                        if (_instance == null)
                        {
                            _instance = new ClientConfigVm();
                        }
                    }
                }
                return _instance;
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        public virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        #region private param
        ObservableCollection<Gds.Model.ConfigModel.ClientConfig.ClientPortModel> _clientModels;
        #endregion

        #region public param
        public ObservableCollection<Model.ConfigModel.ClientConfig.ClientPortModel> ClientModels
        {
            get { return _clientModels; }
            set
            {
                _clientModels = value;
                OnPropertyChanged(nameof(ClientModels));
            }
        }
        #endregion

        #region Function
        /// <summary>
        /// 初始化加载
        /// </summary>
        public void Init()
        {
            ClientModels = new ObservableCollection<Model.ConfigModel.ClientConfig.ClientPortModel>();
            if(MainViewModel.Instance.TaskStartModels!=null)
            {
                foreach (var k in MainViewModel.Instance.TaskStartModels)
                {
                    var controllerList = "";
                    foreach (var w in k.Dic_Controller)
                    {
                        controllerList += w.Value.Address + " - ";
                    }
                    ClientModels.Add(new Model.ConfigModel.ClientConfig.ClientPortModel()
                    {
                        ServerTotalLine = k.TotalLineNo.ToString(),
                        ServerCAddr = controllerList,
                        ClientPort = ""
                    }) ;
                }
            }
        }
        #endregion

        #region ICommand
        #endregion

        #region Event
        #endregion
    }
}
